package com.ruoyi.dynamic.service;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.dynamic.model.pojo.entity.Room;
import com.ruoyi.dynamic.model.pojo.request.app.*;
import com.ruoyi.dynamic.model.pojo.request.crm.CrmRoomSearchRequest;
import com.ruoyi.dynamic.model.pojo.request.sheng.AppShengWebHookRequest;
import com.ruoyi.dynamic.model.pojo.result.app.*;
import com.ruoyi.dynamic.model.pojo.result.crm.CrmRoomInfoResult;
import com.ruoyi.system.api.model.user.AppUser;

import java.util.List;

/**
 * <p>
 * 房间表 服务类
 * </p>
 *
 * @author ${author}
 * @since 2024-11-23
 */
public interface IRoomService extends IService<Room> {

    /**
     * 根据频道号查询房间
     */
    Room getRoomByChannelName(String channelName);


    AppRoomSetResult getUserRoomSet(Long userId);

    /**
     * 校验此用户是否是主持
     */
    AppUser verifyIsBoos(Long userId);


    /**
     * 创建房间
     *
     * @param userId
     * @param request
     * @return
     */
    AppCreateRoomResult createRoom(Long userId, AppCreateRoomRequest request);


    /**
     * 融云创建聊天组
     */
    boolean createRongCloundRoom(String userId, String roomNumber, String groupId, String name);

    /**
     * 创建声网房间号
     *
     * @param number
     * @param userId
     * @return
     */
    String createRtcNumber(String number, Long userId);

    /**
     * 房间详情
     *
     * @param userId
     * @param id
     * @return
     */
    AppRoomInfoResult info(Long userId, Long id);

    /**
     * 房间上麦
     *
     * @param request
     * @param userId
     * @return
     */
    boolean upMai(AppRoomMaiRequest request, Long userId);


    /**
     * 校验
     *
     * @param id
     * @return
     */
    Room verify(Long id);

    /**
     * 房间麦上的用户
     *
     * @param id
     * @param my
     * @param userId
     * @return
     */
    List<AppRoomMaiUserResult> maiUsers(Long id, Integer type, boolean flag, boolean my, Long userId, Integer maiNum);

    /**
     * 房间下麦
     *
     * @param request
     * @param userId
     * @return
     */
    boolean downMai(AppRoomMaiRequest request, Long userId);

    /**
     * 用户加入房间
     *
     * @param userId
     * @param id
     * @return
     */
    AppRoomInfoResult enter(Long userId, Long id);

    /**
     * APP房间搜索
     *
     * @param request
     * @param userId
     * @return
     */
    Pages<AppRoomInfoResult> listPage(AppRoomSearchRequest request, Long userId);

    /**
     * 个人房间封面图
     *
     * @param userId
     * @return
     */
    List<String> cover(Long userId);

    /**
     * 更新房间封面图
     *
     * @param userId
     * @param request
     * @return
     */
    boolean updateCover(Long userId, AppUpdateRoomCoverRequest request);

    /**
     * 房间待连线的列表
     */
    Pages<AppRoomMaiUserResult> lineListPage(AppRoomProgarmSearchRequest pageSearchParam, Long userId);

    /**
     * 取消连线
     */
    boolean cancelLine(Long id, Long userId);

    /**
     * 离开房间
     */
    AppRoomOverResult leave(Long id, Long userId);


    /**
     * 下麦单个玩家
     */
    void downMaiAll(Long id, Long userId);

    /**
     * 下麦单个玩家
     */
    void downMaiByUser(AppRoomDownMaiRequest request, Long userId);

    /**
     * 房间用户列表
     */
    Pages<AppRoomUserInfoResult> userListPage(AppRoomUserSearchRequest request, Long userId);

    /**
     * 房间设置某个用户静音
     */
    Integer isSilence(AppRoomDownMaiRequest request, Long userId);

    /**
     * 实时查询房间在线人数
     */
    Integer lineNum(Long id, Long userId);

    /**
     * 房间申请上麦或者连线
     */
    boolean applyMai(Long userId, AppRoomMaiRequest request);

    /**
     * 房主审核麦位/连线申请
     */
    boolean checkMai(Long userId, AppRoomCheckMaiRequest request);

    /**
     * 撤回连麦申请
     */
    boolean recallMai(Long userId, AppRoomWishCloseRequest request);


    /**
     * 校验麦上用户
     */
    AppRoomMaiUserResult verifyMai(Long roomId, Long userId, String cacheKey);


    /**
     * 获取缓存中的key
     */
    String getRoomCacheKey(String key, Long roomId, Long userId);

    /**
     * 主持房间邀请上麦
     */
    boolean inviteMai(Long userId, AppRoomMaiRequest request);


    /**
     * 查询用户是否在频道内
     *
     * @param roomNumber
     * @param userId
     * @return
     */
    boolean getUserIsChannelStatus(String roomNumber, Long userId);

    /**
     * 后台房间列表
     */
    Pages<CrmRoomInfoResult> crmlistPage(CrmRoomSearchRequest request);


    /**
     * 更新房间类型
     */
    boolean updateType(AppRoomUpdateTypeRequest request, Long userId);

    /**
     * 禁言某个用户
     */
    void banByUser(AppRoomBanByUserRequest request, Long userId);

    /**
     * 取消禁言某个用户
     */
    void cancelBanUser(AppRoomBanByUserRequest request, Long userId);

    /**
     * 收到声网回调
     */
    JSONObject webHookMessage(AppShengWebHookRequest request, String sign);

    /**
     * 离开房间
     */
    void leaveRoom(Long userId, Room room);


}
